<?php
	include "header.php";
	$userid = $_COOKIE['userid'] ? $_COOKIE['userid'] : $_GET['userid'];
	$redis = connect_redis();
	// $rs = $redis->lrange('users',0,-1);
	// //$rs = $redis->rpop('users');
	// var_dump($rs);
	// die;

	$user_list = $redis->sort("users",array("sort"=>"desc","get"=>"user:username:userid*"));

	// 获取我的关注和粉丝列表以及自己的uid
	$users_daynic = $redis->sUnion("follows:userid".$userid,"fans:userid".$userid);
	// var_dump($users_daynic);
	// die;
	$users_daynic[] = $userid;

	// 根据uid获取对应用户下的所有动态
	$user_weibo_list = [];
	foreach ($users_daynic as $key => $value) {
		$user_weibo = $redis->zRevRange("userweibo:list:userid".$value,0,-1);
		$user_weibo_list = array_merge($user_weibo_list,$user_weibo);
	}
	unset($key,$value);

	// 根据weiboid集分别去除对应的微博信息
	$weibo_data = [];
	foreach ($user_weibo_list as $key => $value) {
		$weibo_data[] = [
			"id" => $value,
			"username" => $redis->get("user:username:userid".($redis->hget("weibo:data:weiboid".$value,"userid")))==$_COOKIE['username']?'我自己':$redis->get("user:username:userid".($redis->hget("weibo:data:weiboid".$value,"userid"))),
			"userid" => $redis->hget("weibo:data:weiboid".$value,"userid"),
			"content" => $redis->hget("weibo:data:weiboid".$value,"content"),
			"create_time" => $redis->hget("weibo:data:weiboid".$value,"create_time"),
		];
	}

	// var_dump($weibo_data);
	// die;

	// var_dump($users_daynic);
	// die;

	// $page = isset($_GET['page']) ? intval($_GET['page']) : 0;					// 开始页
	// $pagesize = isset($_GET['pagesize']) ? intval($_GET['pagesize']) : 10;		// 页码

	// $redis = connect_redis();
	// $mysend_list = $redis->zRevRange("userweibo:list:userid".$userid,0,-1);		// 获取我所有动态

	// $weibo_list = array();
	// foreach ($mysend_list as $key => $value) {
	// 	$weibo_list[] = [
	// 		"weibo_id" => $value,
	// 		"userid" => $userid,
	// 		"content" => $redis->hget("weibo:data:weiboid".$value,'content'),
	// 		"create_time" => best_time($redis->hget("weibo:data:weiboid".$value,'create_time')),
	// 	];
	// }
?>

<style>
	.dynic_list {margin-top:35px;}
	.dynic_list ul li {margin-bottom:15px;border-bottom:#ccc 1px dashed;padding:6px 2px;}
	.dynic_list ul li p {font-size:14px;color:#666;margin-top:3px;}
</style>
<div id="content">
	<div class="user_list">
		<h3>最新用户</h3>
		<div>
			<?php
				foreach ($user_list as $key => $value) {
					echo "<a href=\"home.php?uname=".$value."\">".$value."</a> &nbsp;";
				}
			?>
			<!-- <span></span>
			<a href="#">admin</a>
			<a href="#">test</a> -->
		</div>
	</div>
	
	<div class="dynic_list">
		<h3>最新动态</h3>
		<ul>
			<?php
				foreach ($weibo_data as $key => $value) {
					echo '<li>'.
							'<p style="color:red;font-size:15px;">'.$value['username'].' :</p>'.
							$value['content'].
							'<p>'.best_time($value['create_time']).'</p>'.
							'<p>'.
								'<a href="action.php?type=delWeibo&weibo_id">点赞</a> &nbsp;'.
								' <a href="action.php?type=delWeibo&weibo_id">评论</a>'.
							'</p>'.
						'</li>';
				}

			?>

		<!-- 	<li>
				<p style="color:red;font-size:15px;">admin :</p>
				我今天没做啥啊
				<p>6天前</p>
				<p>
					<a href="action.php?type=delWeibo&weibo_id">点赞</a>
					<a href="action.php?type=delWeibo&weibo_id">评论</a>
				</p>
			</li>  -->

		</ul>
	</div>

</div>

			
<?php
include "footer.php";
?>

